package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.DivideService;
import org.dom4j.Element;

/**
 * 划解分成接口
 *
 * @auther dinggaofei
 * @Date 2023/2/7 10:09
 */
public class PayDivideApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getPayDivide")) { // 获取化解分成票据
            String dividebillnum = body.elementText("dividebillnum");
            if (dividebillnum == null || dividebillnum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[dividebillnum]");
            DivideService divideService = (DivideService) SpringContextUtil.getBean("divideService");
            return divideService.getPayDivide(dividebillnum);
        } else if (head.equals("setDividePayInfo")) {//划解分成缴费信息
            String dividebillnum = body.elementText("dividebillnum");
            String paybankdt = body.elementText("paybankdt");
            String bankaffirm = body.elementText("bankaffirm");
            String bankstation = body.elementText("bankstation");
            DivideService divideService = (DivideService) SpringContextUtil.getBean("divideService");
            BaseResult ret = divideService.setDividePayInfo(dividebillnum, paybankdt, bankaffirm, bankstation);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>" + n + "</returninfo>");
            return ret;

        }
        return null;
    }
}
